#include "ImagenGtkmm.h"
using namespace std;

ImagenGtkmm::ImagenGtkmm(const ImagenGtkmm& c) {
    SetX(c.GetX());
    SetY(c.GetY());
    SetContexto(c.GetContexto());
    SetSurface(c.GetSurface());
    SetImage(c.GetImage());
}

ImagenGtkmm& ImagenGtkmm::operator=(const ImagenGtkmm& c) {
    if(this != &c) {
        this -> ~ImagenGtkmm();
        SetX(c.GetX());
        SetY(c.GetY());
        SetContexto(c.GetContexto());
        SetSurface(c.GetSurface());
        SetImage(c.GetImage());
    }
    return *this;
}

void
ImagenGtkmm::Dibujar() {
    cout << "Dibujo un circulo de centro (" 
    << GetX() << "," << GetY() << endl;
}

void ImagenGtkmm::Redimensionar(bool aumentar, bool x, bool y) {
    int n = 5;
    if(!aumentar)
        n = -5;

    if(aumentar || (!aumentar && (image_ptr_->get_width() + n) > 1 && (image_ptr_->get_height() + n) > 1)) {
        image_ptr_ = image_ptr_->scale_simple(image_ptr_->get_width() + n, image_ptr_->get_height() + n, Gdk::INTERP_NEAREST);
        
        Cairo::Format format = Cairo::FORMAT_RGB24;
        if (image_ptr_->get_has_alpha()) {
            format = Cairo::FORMAT_ARGB32;
        }

        // Create a new ImageSurface
        image_surface_ptr_ = Cairo::ImageSurface::create  (format, image_ptr_->get_width(), image_ptr_->get_height());
        // Create the new Context for the ImageSurface
        image_context_ptr_ = Cairo::Context::create (image_surface_ptr_);
        // Draw the image on the new Context
        Gdk::Cairo::set_source_pixbuf (image_context_ptr_, image_ptr_, 0, 0);
        image_context_ptr_->paint();
    }
}